package com.zsk.shop.enums;

import com.zsk.shop.common.utils.ToolUtil;
import com.zsk.shop.model.results.GoodsTypeResult;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * //---
 * //-++
 * //-+-
 * //--+
 * //+--
 * //+-+
 * //++-
 * //+++
 *
 * @author ljh
 * @create 2022/2/21 15:43
 */
public enum EnumGoodsType {

    AGAIN("复购商品", -1),
    ZERO("购买VIP特殊商品", 0),
    ONE("普通商品，会员商品，0元购商品", 1),
    TWO("普通商品，非会员商品，0元购商品", 2),
    THREE("普通商品，会员商品，非0元购商品", 3),
    FOUR("普通商品，非会员商品，非0元购商品", 4),
    FIVE("非普通商品，会员商品，0元购商品", 5),
    SIX("非普通商品，会员商品，非0元购商品", 6),
    SEVEN("非普通商品，非会员商品，0元购商品", 7),
    EIGHT("非普通商品，非会员商品，非0元购商品", 8),
    ;

    String name;
    Integer type;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    EnumGoodsType(String name, Integer type) {
        this.name = name;
        this.type = type;
    }

    public static Integer genType(GoodsTypeResult result) {
        Boolean isVipBuyGoods = ToolUtil.isNotEmpty(result.getIsVipBuyGoods()) ? result.getIsVipBuyGoods() : false;
        Boolean isAgainGoods = ToolUtil.isNotEmpty(result.getIsAgainGoods()) ? result.getIsAgainGoods() : false;
        Boolean isGoods = ToolUtil.isNotEmpty(result.getIsGoods()) ? result.getIsGoods() : false;
        Boolean isVipGoods = ToolUtil.isNotEmpty(result.getIsVipGoods()) ? result.getIsVipGoods() : false;
        Boolean isZoneGoods = ToolUtil.isNotEmpty(result.getIsZoneGoods()) ? result.getIsZoneGoods() : false;
//        return isVipBuyGoods ? 0 : (isGoods ?
//                (isVipGoods ? (isZoneGoods ? 1 : 3) : (isZoneGoods ? 2 : 4))
//                :
//                (isVipGoods ? (isZoneGoods ? 5 : 6) : (isZoneGoods ? 7 : 8)));
        return isAgainGoods ? -1 : (
                isVipBuyGoods ? 0 : (
                        isGoods ? (isVipGoods ? (isZoneGoods ? 1 : 3) : (isZoneGoods ? 2 : 4)) :
                                (isVipGoods ? (isZoneGoods ? 5 : 6) : (isZoneGoods ? 7 : 8))));

    }

    public static GoodsTypeResult getGoodsTypeByType(Integer type) {
        GoodsTypeResult result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(false)
                .isGoods(false).isVipGoods(false).isZoneGoods(false).build();
        switch (type) {
            case -1:
                result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(true)
                        .isGoods(false).isVipGoods(false).isZoneGoods(false).build();
                break;
            case 0:
                result = GoodsTypeResult.builder().isVipBuyGoods(true).isAgainGoods(false)
                        .isGoods(false).isVipGoods(false).isZoneGoods(false).build();
                break;
            case 1:
                result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(false)
                        .isGoods(true).isVipGoods(true).isZoneGoods(true).build();
                break;
            case 2:
                result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(false)
                        .isGoods(true).isVipGoods(false).isZoneGoods(true).build();
                break;
            case 3:
                result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(false)
                        .isGoods(true).isVipGoods(true).isZoneGoods(false).build();
                break;
            case 4:
                result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(false)
                        .isGoods(true).isVipGoods(false).isZoneGoods(false).build();
                break;
            case 5:
                result = GoodsTypeResult.builder().isVipBuyGoods(true).isAgainGoods(false)
                        .isGoods(false).isVipGoods(true).isZoneGoods(true).build();
                break;
            case 6:
                result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(false)
                        .isGoods(false).isVipGoods(true).isZoneGoods(false).build();
                break;
            case 7:
                result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(false)
                        .isGoods(false).isVipGoods(false).isZoneGoods(true).build();
                break;
            case 8:
                result = GoodsTypeResult.builder().isVipBuyGoods(false).isAgainGoods(false)
                        .isGoods(false).isVipGoods(false).isZoneGoods(false).build();
                break;
        }
        return result;
    }

    //1 普通，2 0元购，3 会员商城, 4 特殊 ,5复购
    public static List<Integer> getGoodsTypeByGoodsOrderType(Integer goodsOrderType) {
        List<Integer> result = new ArrayList<>();
        switch (goodsOrderType) {
            case 1:
                result = Arrays.asList(1, 2, 3, 4);
                break;
            case 2:
                result = Arrays.asList(1, 2, 5, 7);
                break;
            case 3:
                result = Arrays.asList(1, 3, 5, 6);
                break;
            case 4:
                result = Arrays.asList(0);
                break;
            case 5:
                result = Arrays.asList(-1);
                break;
        }
        return result;
    }

//    public static void main(String[] args) {
//        GoodsTypeResult result = new GoodsTypeResult();
//        result.setIsVipBuyGoods(false);
//        result.setIsGoods(false);
//        result.setIsZoneGoods(true);
//        result.setIsVipGoods(false);
//        System.out.println(genType(result));
//    }
}
